package algorithm;

import java.util.ArrayList;
import java.util.List;

public class PrintOddEven {
    private static int count = 0;
    private static final Object object = new Object();

    public static void main(String[] args) {
        //new Thread(new Printer(), "偶数线程").start();
        //new Thread(new Printer(), "奇数线程").start();
        List<Integer> list = new ArrayList<>();
        list.add(0, 10);
        list.add(1, 12);
    }

    private static class Printer implements Runnable {
        @Override
        public void run() {
            while (count <= 100) {
                synchronized (object) {
                    System.out.println(Thread.currentThread().getName() + "打印：" + count++);
                    object.notify();
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
